package com.suanfa.dp;

/**
 * 给定数组代表可以跳跃的步数,求最少步数到达终点
 */
public class Jump2 {

    public static void main(String[] args) {
        int[] nums = {1};

        System.out.println(jump(nums));
    }

    public static int jump(int[] nums) {

        int far = 0;
        int step = 0;
        int band = 0;
        for (int i = 0; i < nums.length - 1; i++) {//避免最后多跳一次
            far = Math.max(far, i + nums[i]);
            if (i == band) {//每次选跳点时的最大边界
                band = far;
                step++;
            }
        }
        return step;
    }

}
